package com.iot.north.app.demo.utils;

import java.net.URLEncoder;

/**
 * 通过accessKey计算token
 */
public class TokenUtil {
  public static String assembleToken(
      String path, String timestamp, String accessKey, String accessSecret) throws Exception {
    String encodePath = URLEncoder.encode(path, "UTF-8");
    String data = path + "\n" + timestamp + "\n" + "SHA1";
    String signature = HmacUtil.parseByte2HexStr(HmacUtil.HmacSHA1Encrypt(data, accessSecret));
    return "accessKey="
        + accessKey
        + "&path="
        + encodePath
        + "&timestamp="
        + timestamp
        + "&method="
        + "SHA1"
        + "&sign="
        + signature;
  }
}
